<!DOCTYPE html>

<html lang='en'>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./lib/react.development16.4.0.js"></script>
    <script src="./lib/react-dom.development16.4.0.js"></script>
    <script src="./lib/babel.min.js"></script>
</head>

<body>
    <div id="app">
    </div>
    <script type="text/babel">
         //ref 属性和document.getElementById() 
    
        class MyCom01 extends React.Component {
            render() {
                return (
                    <div>
                        2: <input id="bbb" ref="bbb" type="text"/>
                    </div>
                )
            }
        }
        class MyCom extends React.Component {
            constructor(props) {
                super(props)
                this.handerClick = this.handerClick.bind(this)
            }
             

            handerClick(){
              //let val = document.getElementById('bbb').value;
              let val = this.refs.mycom.refs.bbb.value;
              alert(val);
            }
            render() {
                return (
                    <div>
                        1: <input id="aaa" ref="aaa" type="text"/>
                        <MyCom01 ref="mycom"/>
                        <button onClick={this.handerClick}>点击文本框获得焦点</button>
                    </div>
                )
            }
        }
        
        
        const el = <MyCom/>
        ReactDOM.render(
            el,document.getElementById('app')
        );
    </script>
</body>

</html>